package org.example;

import java.util.ArrayList;
import java.util.List;

class Solution {

    void buildCharCount(String word, int[] charCount) {
        for (int i = 0; i < word.length(); i++) {
            charCount[word.charAt(i) - 'a']++;
        }
    }

    public List<String> commonChars(String[] words) {
        int[] charCount = new int[26];

        buildCharCount(words[0], charCount);

        for (int i = 1; i < words.length; i++) {
            int[] otherCharCount = new int[26];
            buildCharCount(words[i], otherCharCount);
            for (int j = 0; j < charCount.length; j++) {
                charCount[j] = Math.min(charCount[j], otherCharCount[j]);
            }
        }
        List<String> ans = new ArrayList<>();
        for (int i = 0; i < charCount.length; i++) {
            if (charCount[i] == 0) {
                continue;
            }
            String c = String.valueOf((char)(i + 'a'));
            for (int j = 0; j < charCount[i]; j++) {
                ans.add(c);
            }
        }
        return ans;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}